package com.wingsboat;


import com.wingsboat.interfaces.Filter;
import com.wingsboat.interfaces.FilterChain;
import com.wingsboat.interfaces.FilterContext;

/**
 * 过滤器实现
 *
 * @author wangzhong
 */
public abstract class AbstractFilter<T extends FilterContext> implements Filter<T> {
    /**
     * 过滤
     *
     * @param filterContext 过滤内容
     * @param filterChain 当前过滤器链的节点
     */
    @Override
    public void doFilter(T filterContext, FilterChain filterChain) {
        if(filterContext.getFilterSelector().contains(this.getClass().getSimpleName())){
            handle(filterContext);
        }

        filterChain.fireNext(filterContext);
    }


    /**
     * 过滤操作
     * @param filterContext 过滤内容
     */
    protected abstract void handle(T filterContext);
}
